<template>
	<view class="box-detail">
		<view class="item-index-top">
			<view class="item-top-text">{{pageData.model.NAME}}</view>
		</view>
		<view class="box-detail-content" v-if="!showList.length">
			<view class="box-detail-content-item">
				<view class="row-title">主体名称</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系人</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系方式</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">注册地址</view>
				<view class="uni-input form-input">无</view>
			</view>
		</view>
		<view class="box-detail-content" v-for="item,index in showList" v-if='item.leixing!==3' :key="index">
			<view class="box-detail-content-item">
				<view class="row-title">主体名称</view>
				<input class="uni-input form-input" v-model="item.zhutiming_value" @click="showSinglePicker(item,index)" name="input" placeholder="请填写主题名称" disabled=""/>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系人</view>
				<input class="uni-input form-input" v-model="item.lianxiren" name="input" placeholder="请填写联系人" disabled=""/>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系方式</view>
				<input class="uni-input form-input" v-model="item.lianxifang" name="input" placeholder="请填写联系方式" disabled=""/>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">注册地址</view>
				<textarea class="uni-input form-input textarea-style" v-model="item.zhucedi" name="input" placeholder="请填写注册地址" disabled=""/>
			</view>
			<view class="delete-item" @click="deleteItem(index)"></view>
		</view>
		<view class="add-box-detail-content border-wid" @click="addItem()"></view>
		<view class="box-attach">
			<view class="box-detail-content-item">
				<view class="row-title">备注信息</view>
				<textarea class="uni-input textarea-style" v-model="sendData.beizhu" placeholder="请填写备注信息"></textarea>
			</view>
		</view>
		<mpvue-picker :themeColor="themeColor" ref="mpvuePicker1" :mode="mode" :deepLength="deepLength" :pickerValueDefault="pickerValueDefault"
		 @onConfirm="onConfirm1" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mpvue-picker>
	</view>
</template>

<script>
	import mpvuePicker from '@/components/mpvue-picker/mpvuePicker.vue';
	export default {
		components: {
		    mpvuePicker
		},
		data(){
			return{
				themeColor: '#007AFF',
				mode: '',
				deepLength: 1,
				pickerValueDefault: [3],
				pickerValueArray:[],
				showList:[],
				deleteList:[],
				sendData:{
					beizhu:'',
					listData:[],
				},
				activeIndex:0,
				code:'',
				projectId:''
			}
		},
		props: {
			pageData: {
				type: Object,
				default(){
					return {}
				}
			},
			changeListData:{
				type: Object,
				default(){
					return {}
				}
			}
		},
		watch:{
			pageData(){
				this.sendData.beizhu=this.pageData.model.REMARK
				if(this.pageData.dataGrid.proj_subject_view.datas.length){	
					this.sendData.listData=[]
					this.showList=[]
					this.pageData.dataGrid.proj_subject_view.datas.map(item=>{
						this.projectId=item.PROJ_ID
						this.sendData.listData.push({
							datakey:item.DATAKEY,
							proid:item.PROJ_ID,
							zhutiming:item.INVESTOR,//主体名称
							zhutiming_value:'',//主体名称
							lianxiren:item.INVESTOR_B,//联系人
							lianxifang:item.INVESTOR_C,//联系方式
							zhucedi:item.INVESTOR_A,//注册地址
							leixing:0,//操作类型
						})
						if(this.sendData.listData.length){
							this.sendData.listData.map(item=>{
								if(this.changeListData.zhutiList){
									this.changeListData.zhutiList.map(ites=>{
										if(item.zhutiming===ites.CODE){
											item.zhutiming_value=ites.CODE_NAME
										}
									})
								}
							})
						}
						this.showList=this.sendData.listData
					})
				}else{
					this.sendData.listData=[]
					this.showList=this.sendData.listData
				}
			},
			changeListData(){
				if(this.changeListData.zhutiList){
				}
			}
		},
		methods:{
			showSinglePicker(item,index) {
				this.activeIndex=index
				let dataArry=[]
				this.pickerValueArray=[]
				if(this.changeListData.zhutiList){
					dataArry=this.changeListData.zhutiList
					 this.$refs.mpvuePicker1.show()
				}
				dataArry.map(item=>{
					this.pickerValueArray.push(
						{
							label: item.CODE_NAME,
							value: item.CODE
						}
					)
				})
				this.mode = 'selector'
				this.deepLength = 1
				this.pickerValueDefault = [0]
				
			},
			onCancel(e) {
			    console.log(e)
			},
			onConfirm1(e) {
				
				if(this.showList.length){
					this.showList[this.activeIndex].zhutiming_value=e.label
					this.showList[this.activeIndex].zhutiming=e.value[0]
					this.getContactData(e.value[0])
					
				}
			},
			async getContactData(code){
				const res =await this.$req({
					url:'bus/proj/getContact.do',
					data:{one:code}
				})
				if(res.data.success){
					const resData=res.data.data 
					console.log(res.data.data,"eee")
					this.showList[this.activeIndex].lianxiren=resData[0].CONTACT
					this.showList[this.activeIndex].lianxifang=resData[0].CONTACT_NUMBER	
					this.showList[this.activeIndex].zhucedi=resData[0].ZC_ADDRESS
				}
			},
			addItem(){
				this.showList.push({
					datakey: this.getUUID(),
					proid:this.projectId,
					zhutiming:'',//主体名称
					zhutiming_value:'',//主体名称
					lianxiren:'',//联系人
					lianxifang:'',//联系方式
					zhucedi:'',//注册地址
					leixing:1, //操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值0
				})
			},
			deleteItem(index){
				if(index===0&&this.showList.length===1){
					this.showList=[]
				}else{
					if(this.showList[index].leixing===0){
						this.deleteList.push({
							datakey: this.showList[index].datakey,
							proid:this.showList[index].proid,
							zhutiming:this.showList[index].zhutiming,//主体名称
							zhutiming_value:this.showList[index].zhutiming_value,//主体名称
							lianxiren:this.showList[index].lianxiren,//联系人
							lianxifang:this.showList[index].lianxifang,//联系方式
							zhucedi:this.showList[index].zhucedi,//注册地址
							leixing:3, //操作类型  新增
						})
						this.showList.splice(index,1)
					}else if(this.showList[index].leixing===1){
						this.showList.splice(index,1)
						
					}
				}	
			},
			getUUID() {
			   var s = [];
			   var hexDigits = "0123456789abcdef";
			   for (var i = 0; i < 36; i++) {
			    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
			   }
			   s[14] = "4"; 
			   s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); 
			   s[8] = s[13] = s[18] = s[23] = "";
			
			   var uuid = s.join("");
			   return uuid;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding-bottom: 60rpx;
	}
	page{
		padding-bottom: 20rpx;
	}
	.box-detail {
		min-height: 760rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		margin: 20rpx;
		padding: 26rpx 30rpx 50rpx 30rpx;
	}
	.item-index-top{
		// width: 650rpx;
		height: 40rpx;
		// margin: 20rpx 20rpx 18rpx 20rpx;
		background-color: #0099cc;
		border-radius: 10rpx;
		.item-top-text{
			font-family: AlibabaPuHuiTi-Regular;
			padding-left: 20rpx;
			font-size: 26rpx;
			font-weight: normal;
			line-height: 40rpx;
			letter-spacing: 0px;
			color: #ffffff;
		}
	}
	.item-top{
		display: flex;
		justify-content: space-between;
		.setion-left{
			display: flex;
			flex-direction: column;
			.left-text-top{
				font-size: 30rpx;
				font-weight: 600;
				color: #414a5d;
			}
			.left-text-bot{
				margin-top: 22rpx;
				font-size: 26rpx;
				color: #7f7f7f;
			}
		}
		.setion-right{
			display: flex;
			flex-direction: column;
			align-items: flex-end;
			.right-text-top{
				height: 30rpx;
				line-height: 30rpx;
				font-size: 26rpx;
				font-weight: normal;
				color: #9a9a9a;
			}
			.right-text-bot{
				margin-top: 22rpx;
				font-size: 28rpx;
				font-weight: normal;
				color: #999999;
			}
		}
	}
	.box-detail-header {
		display: flex;
		justify-content: space-between;
		margin-bottom: 8rpx;
	
		.name {
			font-size: 30rpx;
			color: #414a5d;
			font-weight: bold;
		}
	
		.date {
			font-size: 26rpx;
			color: #9a9a9a;
		}
	}
	
	.box-net {
		font-size: 26rpx;
		color: #0099cc;
	}
	
	.box-detail-content {
		margin-top: 24rpx;
		padding: 0 10rpx;
		border-bottom: 8rpx solid #e8f0f2;
		position: relative;
	}
	.delete-item{
		width:54rpx;
		height: 54rpx;
		background: url(../../../../static/images/icon_del.png);
		background-size:36rpx 36rpx ;
		background-repeat: no-repeat;
		background-position:18rpx 0; 
		position: absolute;
		z-index: 100;
		top: 100rpx;
		right: 0;
	}
	.add-box-detail-content{
		height: 90rpx;
		background-image: url(../../../../static/images/add.png);
		background-repeat: no-repeat;
		background-position: 50% 50%;
		background-size: 160rpx 46rpx;
		
	}
	// .border {
	// 	;
	// }
	.border-wid{
		border-bottom: 1px solid #e8f0f2
	}
	.box-detail-content-item {
		display: flex;
		flex-direction: row;
		// align-items: center;
		// justify-content: flex-start;
		// justify-content: space-between;
		margin-bottom: 20rpx;
	
		.row-title {
			width: 170rpx;
			font-size: 26rpx;
			color: #414a5d;
			text-align: left;
			flex-shrink: 0;
			margin-right: 10rpx;
	
			&.mag {
				margin-left: 18rpx;
			}
		}
	
		.row-content {
			font-size: 26rpx;
			color: #414a5d;
			word-wrap: break-word;
			word-break: break-all;
			flex: 1;
			text-align: left;
	
			&.mag {
				margin-right: 18rpx;
			}
		}
	}
	
	.bar-contact {
		background-color: #0099cc;
		border-radius: 10px;
		height: 40rpx;
		line-height: 40rpx;
		padding-left: 18rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		
	}
	.box-attach{
		margin-top: 20rpx;
		padding: 0 10rpx;
	}
	.box-attach-row {
		display: flex;
		align-items: center;
		padding: 0 18rpx;
		height: 38rpx;
		margin-bottom: 10rpx;
		.box-attach-icon {
			width: 34rpx;
			margin-right: 30rpx;
		}
		.box-attach-name {
			font-size: 26rpx;
			color: #0099cc;
		}
	}
	.fixed-action-bar{
		width: 100%;
		display: flex;
		height: 70rpx;
		align-items: center;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		.item{
			width: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			
		}
		.icon{
			width: 30rpx;
		}
		.btn-box{
			width: 90rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 70rpx;
		}
		.text-edit{
			font-size: 24rpx;
			color: #0099cc;
			line-height: 70rpx;
		}
		.text-delete{
			font-size: 24rpx;
			color: #cc3357;
			line-height: 70rpx;
		}
	}
	
	.uni-input{
		font-size: 26rpx;
		color: #808080;
		// border-bottom:1px solid #dce4e6;
		flex:1;
	}
	.textarea-style{
		height:156rpx ;
	}
</style>
